/**
 * Copyright (c) Software Institude of PKU
 * All rights reserved. 
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */
package edu.pku.sei.transformation.editor.model;

// imports:
import org.w3c.dom.Element;

import edu.pku.sei.gefcommon.descriptor.annotation.ListProperty;
import edu.pku.sei.gefcommon.descriptor.annotation.MethodProperty;
import edu.pku.sei.modeler.model.common.MetaTypedList;
import edu.pku.sei.modeler.model.xml.XMLUtility;

/**
 * @generated
 * 
 */
public class RuleInvoke extends Relationship {
	// attributes
	public static final int RULE_PRECONDITION = 0;
	public static final int RULE_POSTCONDITION = 1;
	protected int invokeType = RULE_POSTCONDITION;
	private MetaTypedList parameters;

	public RuleInvoke(int type) {
		if (type == RULE_PRECONDITION) {
			this.invokeType = RULE_PRECONDITION;
		} else if (type == RULE_POSTCONDITION) {
			this.invokeType = RULE_POSTCONDITION;
		} else {
			this.invokeType = RULE_POSTCONDITION;
		}
	}

	// getters & setters for attributes

	public int getInvokeType() {
		return invokeType;
	}

	public void setInvokeType(int newInvokeType) {
		int oldinvokeType = invokeType;
		invokeType = newInvokeType;
		firePropertyChange(ModelPackage.RULE_INVOKETYPE, oldinvokeType,
				newInvokeType);
	}

	// getters for references

	public Rule getCallee() {
		return (Rule) targetElement;
	}

	public void setCallee(Rule relation) {
		this.targetElement = relation;
	}

	public Rule getCaller() {
		return (Rule) sourceElement;
	}

	public void setCaller(Rule relation) {
		this.sourceElement = relation;
	}

	@MethodProperty(id = "RELATIONINVOKE_PARAMETER", catalog = "RelationInvoke", name = ModelPackage.RULE_INVOKE_PARAMETER)
	@ListProperty(allowTypes = { RuleInvokeParameter.class }, newInstanceMethod = "newInstance", typeString = ModelPackage.__RULE_INVOKE_PARAMETER__)
	public MetaTypedList getParameters() {
		if (this.parameters == null) {
			this.parameters = new MetaTypedList(RuleInvokeParameter.class,
					this, ModelPackage.__RULE_INVOKE_PARAMETER__);
		}
		return this.parameters;
	}

	// save & load
	public void serialize(Element root) {
		super.serialize(root);
		// attributes

		XMLUtility.xmlInstance.serializeAttribute(root,
				ModelPackage.RULE_INVOKETYPE, invokeType);

		// references
		XMLUtility.xmlInstance.serializeNodes(root,
				ModelPackage.RULE_INVOKE_PARAMETER, this.getParameters());

	}

	public void deSerialize(Element root) {
		super.deSerialize(root);
		// attributes

		invokeType = XMLUtility.xmlInstance.deSerializeInt(root,
				ModelPackage.RULE_INVOKETYPE);

		// references
		this.getParameters().addAll(
				XMLUtility.xmlInstance.deSerializeNodes(root,
						ModelPackage.RULE_INVOKE_PARAMETER));
	}

	public void dynamicSet(String featureID, Object value) {
		if (featureID == null || "".equals(featureID)) {
			return;
		} else
			super.dynamicSet(featureID, value);
	}
}
